///////////////////////////////////////////////////////////////////
// Student name:Jon Hersack and Caleb Reinking
// Course: COSC 3403
// Assignment: #9 - Initial Software Construction
// File name:ScoreKeeper.java
// Purpose: Provides singleton access to scorekeeper, which allows classes
//          to update tracking flags for bonus score modifiers
// Assumptions:none known
// Limitations:none known
// Development Computer:Intel core2 duo 2.67Ghz
// Operating System: windows
// Integrated Development Environment (IDE): netbeans 6.5
// Compiler: Javac: java 1.6.0_13
///////////////////////////////////////////////////////////////////


//singleton design based on
//http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html
public class ScoreKeeper
{
    private static ScoreKeeper instance = null;

    //track number of each played
    int milesTraveled[] = new int[2];
    int safetyCardsPlayed[] = new int[2];
    //if team plays all 4 then bonus 300, other wise only 100 each
    int coupFourresPlayed[] = new int[2];
    boolean delayedAction;//300 to winning team
    int twoHundredsPlayed[] = new int[2];

   //###########################################
   private ScoreKeeper() {

    delayedAction = false;

   }//end constructor


    //###########################################
   public static ScoreKeeper getInstanceOf() {
      if(instance == null) {
         instance = new ScoreKeeper();
      }
      return instance;
   }

   //#############################################
   void resetScoreKeeper()
   {//resets hand flags for next round
    milesTraveled[0] =0;
    milesTraveled[1] =0;
    safetyCardsPlayed[0] = 0;
    safetyCardsPlayed[1] = 0;
    //if team plays all 4 then bonus 300, other wise only 100 each
    coupFourresPlayed[0] = 0;
    coupFourresPlayed[1] = 0;
    delayedAction = false;//300 to winning team
    twoHundredsPlayed[0] = 0;
    twoHundredsPlayed[1] = 0;

    }//end reset

//#################################
    int calculateHandScore(int teamID)
    {
    int additionalScore = 0;
    
    //add score for miles
    additionalScore += addMiles(teamID);
    //add 100 per saftey card played, plus 300 if all 4
    additionalScore += addSafetyBonus(teamID);
    //add 300 per coupFourre
    additionalScore += addCoupBonus(teamID);
    //add 400 for winning the hand
    additionalScore += winBonus(teamID);
    //add 300 if deck was empty
    additionalScore += addDelayBonus(teamID);
    //add 300 if no 200's played
    additionalScore += safeTripBonus(teamID);
    //add 500 if other team played no distance
    additionalScore += shutOutBonus(teamID);

    return additionalScore;
    }//end calculateHandScore

//#################################
    int addMiles(int teamID)
    {
        return milesTraveled[teamID];
    }//end


//#################################
    int addSafetyBonus(int teamID)
    {
        if(safetyCardsPlayed[teamID]==4)
        return 700;//100 per safety plus 300 bonus for all
        else
        return safetyCardsPlayed[teamID]*100;//100 per saftey
    }//end


    //#################################
    int addCoupBonus(int teamID)
    {
        return coupFourresPlayed[teamID]*300;//100 per saftey
    }//end


    //#################################
    int winBonus(int teamID)
    {
        if(milesTraveled[teamID]==1000)
        return 400;//400 for winning
        else
        return 0;
    }//end


    ////#################################
    int addDelayBonus(int teamID)
    {
        checkDelayedAction();
        if(milesTraveled[teamID]==1000 && delayedAction)
        return 300;
        else return 0;
    }

    //#################################
    int safeTripBonus(int teamID)
    {
        if(twoHundredsPlayed[teamID]==0&&milesTraveled[teamID]==1000)
        return 300;
        else return 0;
    }


    //#################################
    int shutOutBonus(int teamID)
    {
        int otherTeamID = (teamID+1)%2;
        if(milesTraveled[otherTeamID]==0 && milesTraveled[teamID]==1000)
        return 500;
        else
        return 0;
    }//end


    //#################################
    void checkDelayedAction()
    {//set delayedACtion to Deck::isempty
        Deck deckStatus = Deck.getInstanceOf();
        delayedAction = deckStatus.isEmpty();
    }//end checkDelayaction


    //#################################
    void setMilesTraveled(int teamID, int miles)
    {//set delayedACtion to Deck::isempty
        milesTraveled[teamID]=miles;
    }//end checkDelayaction


     //#################################
    void incTwoHundredsPlayed(int teamID)
    {//set delayedACtion to Deck::isempty
        twoHundredsPlayed[teamID]++;
    }//end checkDelayaction

    
     //#################################
    void incSafetyPlayed(int teamID)
    {//set delayedACtion to Deck::isempty
        safetyCardsPlayed[teamID]++;
    }//end checkDelayaction

    
     //#################################
    void incCoupPlayed(int teamID)
    {//set delayedACtion to Deck::isempty
       coupFourresPlayed[teamID]++;
    }//end checkDelayaction

    
    //#################################
    public static void main(String [ ] args)
    {
        Deck myDeck = Deck.getInstanceOf();
        
    }// end test main

}//end class Deck


